home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 2010 April
/
PCWorld0410.iso
/
pluginy Firefox
/
48973
/
48973.xpi
/
chrome
/
toolbarbutton.js
< prev
next >
Wrap
Text File
|
2010-02-09
|
2KB
|
50 lines
var DownloadFolderToolbarButton = {
onToolbarButtonCommand: function(e) {
DownloadFolderToolbarButton.openDownloadFolder();
},
openDownloadFolder : function() {
var pref = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefBranch);
var dirService = Components.classes["@mozilla.org/file/directory_service;1"].
getService(Components.interfaces.nsIProperties);
if(pref.getBoolPref("browser.download.useDownloadDir")) {
// Firefox is going to check where to save by file according to the folderList
switch (pref.getIntPref("browser.download.folderList")) {
case 0: // the desktop
var desktop = dirService.get("Desk", Components.interfaces.nsILocalFile);
folder = desktop;
break;
case 1: // the downloads folder
var dm = Components.classes["@mozilla.org/download-manager;1"]
.getService(Components.interfaces.nsIDownloadManager);
folder = dm.userDownloadsDirectory;
break;
case 2: // the last folder specified for a download
folder = pref.getComplexValue("browser.download.dir", Components.interfaces.nsILocalFile);
break;
}
} else {
// Users are manually pointing out a directory to save to
folder = pref.getComplexValue("browser.download.lastDir", Components.interfaces.nsILocalFile);
}
if (folder) {
try {
folder.reveal();
} catch (ex) {
// if nsILocalFile::Reveal failed (eg it currently just returns an
// error on unix), just open the folder in a browser window
alert(ex);
}
} else {
alert("Unable to open folder, please contact me at wybren@zen-ben.com!");
}
}
}